home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Libraries / MacWT 0.04 / turlsLibs / RectUtils.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-31  |  2.2 KB  |  75 lines  |  [TEXT/MMCC]

  1. #define    _H_RectUtils
  2. #ifndef    __RectUtils__
  3. #define    __RectUtils__
  4.  
  5. /* RectUtils.h
  6. **    Macros to cut out making expensive traps for things like SetRect and SetPt!
  7. **
  8. **
  9. **    History
  10. **    =======
  11. **    00    <tur 24-Feb-92>    Basic Version
  12. **    01    <tur 01-May-94> Jazzed up for C++/wt
  13. */
  14.  
  15.  
  16. #ifdef __cplusplus
  17.  
  18.     inline void QSetPt(Point *p, short x, short y)    { p->v = y; p->h = x; }
  19.     inline void ZeroPt(Point *p)                    { p->h = p->v = 0; }
  20.     inline void QSetRect(Rect *rP, short l, short t, short r, short b)
  21.         { rP->top = t; rP->left = l; rP->bottom = b; rP->right = r; }
  22.  
  23.     inline void QInsetRect(Rect *rP, short dx, short dy)
  24.         { rP->top += dy; rP->left += dx; rP->bottom -= dy; rP->right -= dx; }
  25.  
  26.     inline short rectHeight(Rect *rp)    { return rp->bottom - rp->top; }
  27.     inline short rectWidth(Rect *rp)    { return rp->right - rp->left; }
  28.  
  29.     inline int RectInRect(Rect *r1p, Rect *r2p)
  30.         { return (r1p->left >= r2p->left && r1p->right <= r2p->right &&
  31.                   r1p->top >= r2p->top && r1p->bottom <= r2p->bottom); }
  32.  
  33. #else    /* __cplusplus */
  34.  
  35.     #define    ZeroPt(pointPtr)        *((long *)(pointPtr)) = 0
  36.     
  37.     #define    rectHeight(r)            ((r)->bottom - (r)->top)
  38.     #define    rectWidth(r)            ((r)->right - (r)->left)
  39.  
  40.     /* Is "r1" completely enclosed in "r2"? */
  41.     #define    RectInRect(r1p, r2p)    ((r1p)->left >= (r2p)->left && (r1p)->right <= (r2p)->right && \
  42.                                      (r1p)->top >= (r2p)->top && (r1p)->bottom <= (r2p)->bottom)
  43.  
  44.     #define    QSetPt        SetPt
  45.     #define    QSetRect    SetRect
  46.     #define    QInsetRect    InsetRect
  47.  
  48. #endif    /* __cplusplus */
  49.  
  50. #define    SetPt(pointPtr, x, y)    (pointPtr)->v = (y), (pointPtr)->h = (x)
  51. #define    SetRect(rP, l,t,r,b)    (rP)->top = t, (rP)->left = l,                \
  52.                                 (rP)->bottom = b, (rP)->right = r
  53.  
  54. #define    InsetRect(rP, dx, dy)    (rP)->top += (dy), (rP)->left += (dx),        \
  55.                                 (rP)->bottom -= (dy), (rP)->right -= (dx)
  56.     
  57.  
  58. #define    ZeroRect(rP)            ((long *)(rP))[0] = ((long *)(rP))[1] = 0
  59.  
  60.  
  61. #ifndef InsetRectByN
  62.     #define    InsetRectByN(rP, dxy)    InsetRect(rp, dxy, dxy)
  63. #endif  /* InsetRectByN */
  64.  
  65.  
  66. #define    EqualRect(rp1, rp2)        (((long *)(rp1))[0] == ((long *)(rp2))[0] && \
  67.                                 ((long *)(rp1))[1] == ((long *)(rp2))[1])
  68.  
  69. #ifndef    topLeft
  70.     #define topLeft(rekt)        (((Point *) &(rekt))[0])
  71.     #define botRight(rekt)        (((Point *) &(rekt))[1])    /* assume this also... */
  72. #endif    /* topLeft */
  73.  
  74. #endif    /* __RectUtils__ */
  75.